home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / util / gnu / gnu_oleo_1_2_2.lha / oleo-1.2.2 / cmd.h < prev    next >
C/C++ Source or Header  |  1993-03-03  |  6KB  |  201 lines

  1. #ifndef CMDH
  2. #define CMDH
  3.  
  4. /*    Copyright (C) 1992, 1993 Free Software Foundation, Inc.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this software; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19. /*  t. lord    Wed Oct 14 12:01:37 1992    */
  20.  
  21. /*
  22.  * This file explains the generic interface to interactive functions.
  23.  * This covers how C functions are made available to the user, how
  24.  * keymaps are structured.  This also describes the variables that
  25.  * hold the user's interaction state .
  26.  */
  27. #include "line.h"
  28.  
  29.  
  30. /*
  31.  * A set of 26 string buffers, named `a' - `z', hold the default
  32.  * values for strings read from the user.  For example, both
  33.  * visit-spreadsheet and save-spreadsheet use buffer `f'.  Whatever
  34.  * file name the user answers to visit-spreadsheet becomes the default
  35.  * for save-spreadsheet.
  36.  */
  37. extern struct line in_line[];
  38. #define IN_LINE(c)  (&in_line[(C) - 'a'])
  39.  
  40.  
  41. /*
  42.  * These describe C functions that can be called interactively.
  43.  * FUNC_NAME: The name that `execute-function' uses.
  44.  * FUNC_FUNC: The C function the implements the command.
  45.  * FUNC_ARGS: Similar to an emacs interactive string. (see global_cmd)
  46.  *         This is the list of argument types.  When an argument type is
  47.  *    written with a ? after it, it means that an in_line name
  48.  *    should  replace the ?.  For example, `fa' means read a file
  49.  *    name using IN_LINE('a').
  50.  *
  51.  *    C  - Confirm; ask `are you SURE?' (may preceed other args).
  52.  *    r? - Call the C function with a range argument. (`fn(struct range *)')
  53.  *    R? - Call with two range arguments.
  54.  *    t? - Prompt the user for an arbitrary string.
  55.  *    f?mode - Get a file name and pass the opened FILE * to the
  56.  *             function. `mode' is as the last argument to fopen.
  57.  *         The file is closed when the function returns.
  58.  *    F?mode - like f, but passes a range too. (`fn(struct range *, FILE *)')
  59.  *    S? - passes a string and range (`fn(char *, struct range *)')
  60.  *    ndigit - Pass along the digit converted to an integer.
  61.  *     Tdigit - Pass digit and the last character typed to invoke the command.
  62.  *      N  - pass along the integer argument passed to global_cmd.
  63.  *
  64.  * FUNC_FLAGS: see #defines below
  65.  */
  66. typedef void (*interactive_function) ();
  67.  
  68. struct cmd_func
  69. {
  70.   char *func_name;
  71.   char *func_args;
  72.   int func_flags;
  73.   interactive_function func_func;
  74. };
  75.  
  76. /* for func_flags */
  77. #define NONTOP    0x1
  78. #define TOPLN    0x2
  79. #define ALL    0x3
  80. #define WTH_CHR 0x4
  81. #define BRK    0x8
  82. #define NC    0x10
  83.  
  84. /*
  85.  * There is a 2d (argv style) array of command functions.  Each 0 dimension
  86.  * slice is called a `vector'.  The first two vectors have a hardwired use.
  87.  * Other vectors can be added by reallocing the_funcs and incrementing
  88.  * num_funcs.
  89.  *
  90.  * When looking for a function of a particular name, the array is
  91.  * searched in vector-major order.
  92.  */
  93. extern int num_funcs;
  94. extern struct cmd_func **the_funcs;
  95. #define OLEO_VECTOR (0)        /* all oleo's builtins except: */
  96. #define EDIT_VECTOR (1)        /* input area editting commands */
  97.  
  98.  
  99.  
  100. /*
  101.  * Keymaps and keybinds are next.
  102.  * Within a keymap, keys are bound to a `struct key'.
  103.  *
  104.  * Normally,  `the_funcs[akey.vector][akey.code]' is the command binding of a
  105.  * key.  However, the akey.vector == -1, then the binding is to another
  106.  * keymap, found by the_maps[akey.code].  The final exception, is that if
  107.  * both vector and code are -1, then the key is unbound.
  108.  */
  109. struct key
  110. {
  111.   short vector;
  112.   short code;
  113. };
  114.  
  115. struct keymap
  116. {
  117.   struct keymap *map_next;
  118.   struct key keys[256];
  119. };
  120. extern int num_maps;
  121. extern struct keymap **the_maps;
  122. extern char **map_names;
  123.  
  124. #define UNBOUND        0
  125. #ifndef CTRL
  126. #define CTRL(X) ((X)&037)
  127. #endif
  128. #ifndef META
  129. #define META(X) ((X)|0200)
  130. #endif
  131.  
  132. /*
  133.  * Keymap names.  They can be used as indices into the_maps and map_names.
  134.  */
  135. #define MAIN_MAP map_id("main")
  136. #define EDIT_MAP map_id("edit")
  137. #define DIGIT_MAP map_id("digit")
  138. #define NAVIGATE_MAP map_id("navigate")
  139. extern int map_id ();
  140.  
  141.  
  142. struct macro
  143. {
  144.   struct macro *mac_prev;
  145.   unsigned char *mac_exe;
  146.   int mac_flags;
  147.   CELLREF mac_row, mac_col;
  148.   struct rng mac_rng;
  149. };
  150.  
  151. extern int n_bound_macros;
  152. extern struct obstack macro_stack;
  153. extern struct rng *bound_macros;
  154. extern int bound_macro_vec;
  155. extern unsigned char *making_macro;
  156. extern unsigned char *making_macro_start;
  157. extern unsigned int making_macro_size;
  158.  
  159.  
  160. /*
  161.  * The following variables control oleo's decisions about which iteractive
  162.  * functionsto call.
  163.  */
  164.  
  165. extern struct macro *rmac;        /* Currently executing macro, if any. */
  166. extern char *macro_func_arg;
  167.  
  168. extern int cur_chr;        /* Last character typed by the user. */
  169.  
  170. extern short cur_vector;    /* Currently selected function vector. */
  171. extern struct cmd_func *cur_cmd;/* Currently executing command. */
  172.  
  173. /*
  174.  * MAP_CHR takes a keymap number (index into the_maps) as argument,
  175.  * and advances the state of the above variables.  If a macro is executing,
  176.  * it will consume characters from the macro.  Otherwise, characters
  177.  * are read from the keyboard.  MAP_CHR does not execute the newly
  178.  * selected command (in fact, if an unbound key is read, cur_cmd will be set
  179.  * to 0).
  180.  */
  181.  
  182. #ifdef __STDC__
  183. extern void map_char (int);
  184. #else
  185. extern void map_char ();
  186. #endif
  187.  
  188.  
  189. /*
  190.  * GLOBAL_CMD executes cur_cmd, providing arguments in the manner
  191.  * described above (see FUNC_ARGS).
  192.  *
  193.  * Return values:
  194.  *    -3    break key!
  195.  *    -2    c is inappropriate
  196.  *    -1    C is OK
  197.  *    0+    New char value is ret-1;
  198.  */
  199. extern unsigned int how_many;    /* The numeric prefix argument. */
  200. #endif
  201.